{	Problem: http://codeforces.ru/problemset/problem/1/B
	Verdict: Accepted
}
uses sysutils;
var t,l,r,c,k,cur:int64; s,st:string; f:boolean; i,j,n:longint; a:array[0..5] of int64;
begin
readln(n);
a[0]:=1;
a[1]:=26;
a[2]:=676;
a[3]:=a[2]*a[1];
a[4]:=a[2]*a[2];
a[5]:=a[4]*a[1];
for i:=1 to n do begin
  readln(s);
  f:=false;
  t:=1;
  l:=0;
  for j:=1 to length(s) do
    if s[j] in ['0'..'9'] then begin
      f:=true;
      if l=0 then l:=j;
    end else
    if f then t:=2;
  if t=1 then begin
    st:=copy(s,1,l-1);
    r:=strtoint(copy(s,l,length(s)-l+1));
    c:=0;
    for j:=length(st) downto 1 do inc(c,(ord(st[j])-64)*a[length(st)-j]);
    writeln('R',r,'C',c);
  end else begin
    delete(S,1,1);
    r:=strtoint(copy(s,1,pos('C',s)-1));
    delete(s,1,pos('C',s));
    c:=strtoint(s);
    st:='';
    cur:=1;
    while c>0 do begin
      k:=((c-1) mod a[cur]+1) div a[cur-1];
      st:=st+chr(k+64);
      dec(c,k*a[cur-1]);
      inc(cur);
    end;
    for j:=length(st) downto 1 do write(st[j]);
    writeln(r);
  end;
end;
end.